package com.yootk.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * 读取资源文件
 */
@RestController
@RequestMapping("/i18n/*")
public class I18NAction {

    @Autowired
    private MessageSource messageSource;    // 消息资源

    @RequestMapping("base")
    public Object showBase() {
        Map<String, String> map = new HashMap<>();
        map.put("message", messageSource.getMessage("yootk.message", null, Locale.getDefault()));
        map.put("url", messageSource.getMessage("yootk.url", null, Locale.getDefault()));
        return map;
    }

    @RequestMapping("locale")
    public Object showLocale(Locale loc) {
        Map<String, String> map = new HashMap<>();
        map.put("message", messageSource.getMessage("yootk.message", null, loc));
        map.put("url", messageSource.getMessage("yootk.url", null, loc));
        return map;
    }
}
